package com.thread;

import com.github.sarxos.webcam.Webcam;

import java.awt.*;
import java.awt.image.BufferedImage;

/**
 * Author：hanll
 * ClassName：RunVideoThread
 * Date：2022/11/1 11:17
 * Version：1.0
 * Description：
 */
public class RunVideoThread implements Runnable{

    private boolean flag;

    private Webcam webcam;

    private Graphics graphics;

    public RunVideoThread(Webcam webcam, Graphics graphics) {
        this.webcam = webcam;
        this.graphics = graphics;
    }

    public void open() {
        flag = true;
    }

    public void close() {
        flag = false;
    }

    @Override
    public void run() {
        while (flag) {
            BufferedImage bufferedImage = webcam.getImage();
            graphics.drawImage(bufferedImage, 250, 150, null);
        }
    }
}
